using System;
using System.Collections.Generic;
using System.Data;

namespace TAProject.UI
{
    class DataTableComparer : IEqualityComparer<DataRow>
    {
        private readonly string _columnHeader;

        public DataTableComparer(string columnHeader)
        {
            _columnHeader = columnHeader;
        }

        public bool Equals(DataRow x, DataRow y)
        {
            if(x[_columnHeader].GetType() == typeof(int))
                return x.Field<int>(_columnHeader) == y.Field<int>(_columnHeader);
            if (x[_columnHeader].GetType() == typeof(string))
                return x.Field<string>(_columnHeader) == y.Field<string>(_columnHeader);
            if(x[_columnHeader].GetType() == typeof(DateTime))
                return x.Field<DateTime>(_columnHeader).ToShortDateString() == y.Field<DateTime>(_columnHeader).ToShortDateString();
            return false;
        }

        public int GetHashCode(DataRow obj)
        {
            return obj.ToString().GetHashCode();
        }
    }

    public class ComboBoxItemsComparer<T> : IEqualityComparer<ComboBoxFiller<T>>
    {
        public bool Equals(ComboBoxFiller<T> x, ComboBoxFiller<T> y)
        {
            return x.ToString() == y.ToString();
        }

        public int GetHashCode(ComboBoxFiller<T> obj)
        {
            return obj.ToString().GetHashCode();
        }
    }

    public class AllTypesItemsComparer<T> : IEqualityComparer<T>
    {
        public bool Equals(T x, T y)
        {
            return x.ToString() == y.ToString();
        }

        public int GetHashCode(T obj)
        {
            return obj.ToString().GetHashCode();
        }
    }
}